
<html>
<head>
    <title>查看请假申请</title>
    <script src="js/jquery-3.3.1.min.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.css">
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <script src="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.js"></script>
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
    
    <link href="https://cdn.bootcss.com/mdui/0.4.3/css/mdui.min.css" rel="stylesheet">
    <script src="js/mdui.min.js"></script>
    
    

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.css">
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://unpkg.com/bootstrap-table@1.14.2/dist/bootstrap-table.min.js"></script>
    <!-- Latest compiled and minified Locales -->
    <script src="https://unpkg.com/bootstrap-table@1.14.2/dist/locale/bootstrap-table-zh-CN.min.js"></script>


</head>
<style type="text/css">
    .mdui-btn{
        margin-right: 5px;
    }
</style>

<body class="mdui-theme-primary-light-blue mdui-theme-accent-blue">
    <h2 class="mdui-text-color-theme">查看请假申请</h2>
    <div id="content">
       <div id="tableArea">
           <table id="table"></table>
       </div>
    </div>

    <div id="record" class="mdui-dialog">
        <div class="mdui-dialog-content">
            <div class="mdui-dialog-title">学生信息</div>
            <div>

                <div id="basicInfoLabel" class="mylabel" >一、学生基本信息</div>

                <form action="" id="detail_form">
                <div class="mdui-textfield">
                    <label class="mdui-textfield-label">学生姓名</label>
                    <input class="mdui-textfield-input" type="text" id="userName" name="userName" readonly/>
                    <div class="mdui-textfield-error">此项不能为空</div>
                </div>

                <div class="mdui-textfield">
                    <label class="mdui-textfield-label">学部</label>
                    <input class="mdui-textfield-input" type="text" id="depName" name="depName" readonly required/>
                    <div class="mdui-textfield-error">此项不能为空</div>
                </div>

                <div class="mdui-textfield">
                    <label class="mdui-textfield-label">班级</label>
                    <input class="mdui-textfield-input" type="text" id="clazzName" name="clazzName" readonly required/>
                    <div class="mdui-textfield-error">此项不能为空</div>
                </div>

                <div class="mdui-textfield">
                    <label class="mdui-textfield-label">宿舍楼</label>
                    <input class="mdui-textfield-input" type="text" id="dormitoryBuildId" name="dormitoryBuildId" readonly required/>
                    <div class="mdui-textfield-error">此项不能为空</div>
                </div>

                <div class="mdui-textfield">
                    <label class="mdui-textfield-label">房间号</label>
                    <input class="mdui-textfield-input" type="text" id="dormitoryHouseId" name="dormitoryHouseId" readonly required/>
                    <div class="mdui-textfield-error">此项不能为空</div>
                </div>

                <div class="mdui-textfield">
                    <label class="mdui-textfield-label">学生电话</label>
                    <input class="mdui-textfield-input" type="text" id="userPhone" name="userPhone" readonly  required/>
                    <div class="mdui-textfield-error">此项不能为空</div>
                </div>

            

                

                

                </form>
            </div>


        </div>
        <div class="mdui-dialog-actions">
            
            <button class="mdui-btn mdui-ripple" mdui-dialog-close>关闭</button>
        </div>
    </div>


    
        
</body>

<script>
    var $$=mdui.JQ;
    var teaid = JSON.parse(sessionStorage.getItem("userid"))
    
    var detailDialog=new mdui.Dialog("#record");
    window.operateEvents={
        "click .detail":function (index,value,row){
            rm()
            getDetail(row.userId)
        },
        "click .status":function(index,value,row){
            changeSubmit(row.leaveId,row.leaveState,row.userId)
        },
        "click .delete":function(index,value,row){
            deleteSubmit(row.leaveId)
        }
    }
    
  
   var now = new Date();
        var year = now.getFullYear(); //得到年份
         var month = now.getMonth()+1;//得到月份
         console.log(month)
          var date = now.getDate();//得到日期
          function PrefixInteger(num, length) {
 return (Array(length).join('0') + num).slice(-length);
}
        month=PrefixInteger(month,2);
        date=PrefixInteger(date,2);
          var time = "";
        time = year + "-" + month + "-" + date  ;
        console.log(time);


    
        $("#table").bootstrapTable({
        url: 'http://prehealth.top/pre2.0/Leave?clazz_teacher_id='+teaid+'&date='+time,         //请求后台的URL（*）
        method: 'get',                      //请求方式（*）
        toolbar: '#toolbar',                //工具按钮用哪个容器
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: true,                   //是否显示分页（*）
        sortOrder: "asc",                   //排序方式
        //    queryParams: oTableInit.queryParams,//传递参数（*）
        sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
        smartDisplay:true,
        pageNumber: 1,                       //初始化加载第一页，默认第一页
        pageSize: 9,                       //每页的记录行数（*）
        pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
        search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
       // showColumns: true,                  //是否显示所有的列
        showRefresh: true,                  //是否显示刷新按钮
        minimumCountColumns: 2,             //最少允许的列数
         clickToSelect: true,                //是否启用点击选中行
        height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
        uniqueId: "leaveId",                     //每一行的唯一标识，一般为主键列
        showExport: true,                     //是否显示导出
        exportDataType: "basic",
        columns: [ {
            field:'leaveId',
            title:'申请编号',
            align:'center'
            
        },{
            field:'userId',
            title:'申请人',
            align:'center',
            formatter:getName
            
        },{
            field:'leaveType',
            title:'请假类别',
            align:'center',
            formatter:gettype
        } ,{
            field:'leaveStartDate',
            title:'请假时间' ,
            align:'center',
            formatter:add
            
        },{
            field:'leaveText',
            title:'请假说明',
            align:'center'
            
        } ,{
            field:'leavePostDate',
            title:'申请时间',
            align:'center',
            
        },{
            field:'leaveState',
            title:'申请状态',
            align:'center',
            formatter:status
        },{
            field: 'operation',
            title: '操作',
            align: 'center',
            events:operateEvents,//给按钮注册事件
            formatter:addFunctionAlty//表格中增加按钮 
        }
        ]
    })
 
    function add(value,row,index){
        return [row.leaveStartDate+'至'+row.leaveEndDate].join('');
    }
    function gettype(value,row,index){
        switch(row.leaveType){
            case 0:
                return ['<span>事假</span>'].join('');
                break;
            case 1:
                return ['<span>病假</span>'].join('');
                break;
        }
    }

    function getuserName(userId){
        var username;
        $$.ajax({
            url:"http://prehealth.top/pre2.0/userinfo/"+userId,
            method:"get",
            dataType:"json",
            data:{
                  user_id:userId,
                  
              },
              contentType:false,
              async: false,
              success:function(data){
                 username=data.userName;
                 console.log(username)
                 
               }});
        
            return username;
        

    }
        
    function getName(value,row,index){
        var userqqq=getuserName(row.userId);

        return ['<span>'+userqqq+'</span>'].join('');

    }      
    
    

    
    function status(value,row,index){

        switch(row.leaveState){
            case 0:
                return ['<span>驳回</span>'].join('');
                break;

            case 1:
                return ['<span>通过</span>'].join('');
                break;

            case 2:
                return ['<span>未核审</span>'].join('');
                break;

        }
    }

    function addFunctionAlty(){
        return[
            '<button class="mdui-btn mdui-color-theme-accent mdui-ripple detail"> 查看申请人信息</button>',
            '<button class="mdui-btn mdui-color-theme-accent mdui-ripple status">审批</button>',
            '<button class="mdui-btn mdui-color-theme-accent mdui-ripple delete">删除申请</button>'
        ].join('')
    }
   

    
    
    function rm() {
        $(".myimg").remove();
    }

     function getDetail(userId) {
        console.log(userId)
        $$.ajax({
            url:"http://prehealth.top/pre2.0/userinfo/"+userId,
            method:"get",
            dataType:"json",
            data:{
                  user_id:userId,
                  
              },
            contentType:false,
            success:function (data) {
                
                 $$("#userName").val(data.userName);
                 $$("#depName").val(data.department.depName);
                 $$("#clazzName").val(data.clazz.clazzName);
                 $$("#dormitoryBuildId").val(data.dormitory.dormitoryBuildId);
                 $$("#dormitoryHouseId").val(data.dormitory.dormitoryHouseId);
                 $$("#userPhone").val(data.userPhone);
                detailDialog.open();

                
            }
        })
    }

    function changeSubmit(leaveId,leaveState,userId) {
        var touser;
         var name;
            $$.ajax({
            url:"https://prehealth.top/pre2.0/login",
            method:"get",
            dataType:"json",
            async: false,
            data:{
                  user_id:userId
                  
              },
              contentType:false,
             
              success:function(data){
                 touser=data.userOpenId;
                 name = data.userinfo.userName;
                 console.log(touser)
                 
               }});


            var json1 = 
    
    {
        "touser":touser,
        "template_id":"gDRFcTh876M6Wn-_VtV2iJQF_D0e9-Zfc6ye-p7N9j0",
        "miniprogram_state":"developer",
        "lang":"zh_CN",
        "data":{
          "name1":{
            "value":name
          },
          "phrase3":{
            "value":"已审核"
          },
          "thing4":{
            "value":"请假申请通过"
          },
          "thing6":{
            "value":"已通过审批"
          }

        }
    };
         var json2 = 
    
    {
        "touser":touser,
        "template_id":"gDRFcTh876M6Wn-_VtV2iJQF_D0e9-Zfc6ye-p7N9j0",
        "miniprogram_state":"developer",
        "lang":"zh_CN",
        "data":{
          "name1":{
            "value":name
          },
          "phrase3":{
            "value":"已审核"
          },
          "thing4":{
            "value":"请假申请被驳回"
          },
          "thing6":{
            "value":"请假失败"
          }

        }
    };

          
          mdui.dialog({
           title: '审批状态',
            
          buttons: [
        {
          text: '不通过',
          onClick: function(inst){
          
           $$.ajax({
            method: 'POST',
            url: 'https://prehealth.top/pre2.0/Send',
            contentType:'application/json;charset=utf-8',
            async: false,
            dataType: "json",
            data:JSON.stringify(json2),
                  
              
            success: function (data) {
                console.log("发送通知成功！")
            },
            fail:function () {
                
            }
        });

           mdui.snackbar({
            message: '上传中...',
            position: 'right-top'
        });
        $$.ajax({
            method: 'PUT',
            url: 'http://prehealth.top/pre2.0/updateLeave',
            dataType: "json",
              data:{
                  leaveId:leaveId,
                  leaveState:0
              },
            success: function (data) {
                $$("#submit").removeAttr("disabled");
                mdui.snackbar({
                    message: '修改成功',
                    position: 'right-top'
                });
                history.go(0)
            },
            fail:function () {
                $$("#submit").removeAttr("disabled");
                mdui.snackbar({
                    message: '修改失败',
                    position: 'right-top'
                });
            }
        });
          
        }

        },
        {
        text: '通过',
        onClick: function(inst){
          
           $$.ajax({
            method: 'POST',
            url: 'https://prehealth.top/pre2.0/Send',
            contentType:'application/json;charset=utf-8',
            async: false,
            dataType: "json",
            data:JSON.stringify(json1),
                  
              
            success: function (data) {
                console.log("发送通知成功！")
            },
            fail:function () {
                
            }
        });

           mdui.snackbar({
            message: '上传中...',
            position: 'right-top'
        });
        $$.ajax({
            method: 'PUT',
            url: 'http://prehealth.top/pre2.0/updateLeave',
            dataType: "json",
              data:{
                   leaveId:leaveId,
                  leaveState:"1"
              },
            success: function (data) {
                $$("#submit").removeAttr("disabled");
                mdui.snackbar({
                    message: '修改成功',
                    position: 'right-top'
                });
                history.go(0)
            },
            fail:function () {
                $$("#submit").removeAttr("disabled");
                mdui.snackbar({
                    message: '修改失败',
                    position: 'right-top'
                });
            }
        });
          
        }
      }
    ]
  });
};

 function deleteSubmit(Leave_id) {

          
          mdui.dialog({
           title: '删除申请',
            content: '您想要删除申请吗？',
          buttons: [
        {
          text: '取消'
        },
        {
        text: '确认',
        onClick: function(inst){
          

           mdui.snackbar({
            message: '删除中...',
            position: 'right-top'
        });
        $$.ajax({
            method: 'DELETE',
            url: 'http://prehealth.top/pre2.0/deleteLeave/'+Leave_id,
            dataType: "json",
              data:{
                  Leave_id:Leave_id
                  
              },
            success: function (data) {
                $$("#submit").removeAttr("disabled");
                mdui.snackbar({
                    message: '删除成功',
                    position: 'right-top'
                });
                history.go(0)
            },
            fail:function () {
                $$("#submit").removeAttr("disabled");
                mdui.snackbar({
                    message: '删除失败',
                    position: 'right-top'
                });
            }
        });
          
        }
      }
    ]
  });
};
</script>

</html>
